package uk.co.jonlt.AndBusTest;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class BusAdapter extends BaseAdapter implements OnClickListener {
    private Context context;

    private List<Bus> listBus;

    public BusAdapter(Context context, List<Bus> listBus) {
        this.context = context;
        this.listBus = listBus;
    }

	public int getCount() {
        return listBus.size();
    }

    public Object getItem(int position) {
        return listBus.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup viewGroup) {
        Bus entry = listBus.get(position);
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.bus_row, null);
        }
        TextView tvRoute = (TextView) convertView.findViewById(R.id.busRoute);
        tvRoute.setText(entry.getRoute());

        TextView tvDestination = (TextView) convertView.findViewById(R.id.busDestination);
        tvDestination.setText(entry.getDestination());

        TextView tvTime = (TextView) convertView.findViewById(R.id.busTime);
        tvTime.setText(entry.getTime());

        return convertView;
    }

    public void onClick(View view) {
        Bus entry = (Bus) view.getTag();
        listBus.remove(entry);
        notifyDataSetChanged();

    }
}


